package Interfaz;
import Modelo.Author;
import java.util.Vector;

public class ListaAutoresGui extends javax.swing.JDialog {
    
    private Vector autores;
    
    public ListaAutoresGui(java.awt.Frame parent, boolean modal, Vector autore) {
        super(parent, modal);
        initComponents();
        autores=autore;
        String datos[][] = new String[autores.size()][3];
        String titulos[] = {"Nombre", "Apellido", "e-mail"};
        javax.swing.JTable tabla = new javax.swing.JTable(datos, titulos);
        jTablaAutor.setModel(tabla.getModel());
        
        for(int i=0;i<autores.size();i++){
            Author autor = (Author) autores.get(i);
            jTablaAutor.setValueAt(autor.getName(), i, 0);
            jTablaAutor.setValueAt(autor.getSurname(), i, 1);
            jTablaAutor.setValueAt(autor.getEmail(), i, 2);
        }
    }
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        jTablaAutor = new javax.swing.JTable();
        jBtnEliminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setAlwaysOnTop(true);
        setModal(true);
        jTablaAutor.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Name", "Surname", "e-mail"
            }
        ));
        jScrollPane1.setViewportView(jTablaAutor);

        jBtnEliminar.setText("Remove selected");
        jBtnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBtnEliminar))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtnEliminar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBtnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnEliminarActionPerformed
        autores.removeElementAt(jTablaAutor.getSelectedRow());
        String datos[][] = new String[autores.size()][3];
        String titulos[] = {"Nombre", "Apellido", "e-mail"};
        javax.swing.JTable tabla = new javax.swing.JTable(datos, titulos);
        jTablaAutor.setModel(tabla.getModel());
        
        for(int i=0;i<autores.size();i++){
            Author autor = (Author) autores.get(i);
            jTablaAutor.setValueAt(autor.getName(), i, 0);
            jTablaAutor.setValueAt(autor.getSurname(), i, 1);
            jTablaAutor.setValueAt(autor.getEmail(), i, 2);
        }
    }//GEN-LAST:event_jBtnEliminarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnEliminar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTablaAutor;
    // End of variables declaration//GEN-END:variables
    
}
